<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/datepicker.html.php';?>
<style type="text/css">
  .table-condensed td, .table-condensed th {
    padding: 5px 10px;
  }
  .table-condensed .colhead.text-center th {
    padding: 0;
    text-align: center;
  }
  .table-condensed td.date, .table-condensed th.date {
    padding: 5px 2px;
  }
  .w-65px {
    width: 65px !important;
  }
  .w-50px {
    width: 50px !important;
  }
  .ellipsis {
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    max-width: 100%;
    width: 100%;
  }
  .tooltip .tooltip-inner {
    max-width: 100%;
    width: 100%;
  }
  .bold {
    font-weight: bold;
  }
</style>
<div id='mainContent' class='main-row'>
  <div class='side-col col-lg'>
    <?php include 'blockreportlist.html.php';?>
  </div>
  <div class='main-col'>
    <div class='cell'>
      <form method='post'>
        <div class="row" id='conditions'>
          <div class='col-sm-2'>
            <div class='input-group'>
              <span class='input-group-addon'><?php echo $lang->report->project;?></span>
              <?php echo html::select('project', $projects, $project, "class='form-control chosen' onchange='changeParams(this)'");?>
            </div>
          </div>
          <div class='col-sm-2'>
            <div class='input-group'>
              <span class='input-group-addon'><?php echo $lang->report->dept;?></span>
              <?php echo html::select('dept', $depts, $dept, "class='form-control chosen' onchange='changeParams(this)'");?>
            </div>
          </div>
          <div class='col-sm-2'>
            <div class='input-group'>
              <span class='input-group-addon'><?php echo $lang->report->user;?></span>
              <?php echo html::select('user', $users, $user, "class='form-control chosen' onchange='changeParams(this)'");?>
            </div>
          </div>
          <div class='input-group w-400px input-group-sm'>
            <span class='input-group-addon'><?php echo $lang->report->taskOverData;?></span>
            <div class='datepicker-wrapper datepicker-date'><?php echo html::input('begin', $begin, "class='form-control' style='padding-right:10px' onchange='changeParams(this)'");?></div>
            <span class='input-group-addon fix-border'><?php echo $lang->report->to;?></span>
            <div class='datepicker-wrapper datepicker-date'><?php echo html::input('end', $end, "class='form-control' style='padding-right:10px' onchange='changeParams(this)'");?></div>
          </div>
<!--          <div class='col-sm-2'>
	    <?php /*echo html::submitButton($lang->report->query, '', 'btn btn-primary btn-block');*/?>
          </div>-->
        </div>
      </form>
    </div>
    <?php if(empty($taskSummary)):?>
    <div class="cell">
      <div class="table-empty-tip">
        <p><span class="text-muted"><?php echo $lang->error->noData;?></span></p>
      </div>
    </div>
    <?php else:?>
    <div class='cell'>
      <div class='panel'>
        <div class="panel-heading">
          <div class="panel-title"><?php echo $title;?></div>
            <?php
            $checkObject = new stdclass();
            $checkObject->project = 0;
            ?>
          <nav class="panel-actions btn-toolbar"><?php if(common::hasPriv('report', 'export', $checkObject)) echo html::submitButton($lang->report->export, '', 'btn btn-primary btn-block');?></nav>
        </div>
        <div data-ride='table'>
          <table class='table table-condensed table-striped table-bordered table-fixed no-margin table-hover' id="taskSummary">
            <thead>
              <tr class='colhead text-center'>
                <th class="w-60px"><?php echo $lang->report->finishedByAB;?></th>
                <th class="w-110px"><?php echo $lang->report->code;?></th>
                <th class="w-110px"><?php echo $lang->report->projectName;?></th>
                <th class="w-40px"><?php echo $lang->report->id;?></th>
                <th class="w-130px"><?php echo $lang->report->taskName;?></th>
                <th class="w-65px date"><?php echo $lang->report->estStarted;?></th>
                <th class="w-65px date"><?php echo $lang->report->realStarted;?></th>
                <th class="w-65px date"><?php echo $lang->report->deadline;?></th>
                <th class="w-100px"><?php echo $lang->report->finishedDate;?></th>
                <th class="w-50px"><?php echo "最初<br/>预计";?></th>
                <th class="w-50px"><?php echo "总任<br/>务数";?></th>
                <th class="w-50px"><?php echo '任务<br/>总工时';?></th>
                <th class="w-50px"><?php echo "用户<br/>总工时"?></th>
              </tr>
            </thead>
            <tbody>
            <?php
            $color = false;
            $totalPreTime = 0;
            $totalTasks = 0;
            $totalTaskTime = 0;
            $totalUserTime = 0;
            ?>
            <?php foreach($taskSummary as $account => $load):?>
                <?php if(!isset($users[$account])) continue;?>
                <tr class="text-center">
                    <td rowspan="<?php echo (count($load['taskSum']));?>"><?php echo $users[$account];?></td>
                    <?php $id = 1;?>
                    <?php foreach($load['projects'] as $project => $info):?>
                        <?php $class = $color ? 'rowcolor' : '';?>
                        <?php if($id != 1) echo '<tr class="text-center">';?>
                        <td rowspan="<?php echo $info['count'];?>" class="text-left"><div class="ellipsis" data-toggle="tooltip" data-placement="top" title='<?php echo $info['code']; ?>'><?php echo $info['code'];?></div></td>
                        <td rowspan="<?php echo $info['count'];?>" class="<?php echo $class;?> text-left"><div class="ellipsis" data-toggle="tooltip" data-placement="top" title='<?php echo $project?>'><?php echo html::a($this->createLink('project', 'view', "projectID={$info['projectID']}"), $project);?></div></td>
                        <?php $tid = 1;?>
                        <?php foreach($load['tasks'] as $key => $projectTask):?>
                            <?php if ($project == $key): ?>
                            <?php foreach($projectTask as $pName => $taskInfo):?>
                                <?php if($tid != 1) echo '<tr class="text-center">';?>
                                    <td class="gray" style="padding: 0;text-align: center;"><?php echo $taskInfo['id'];?></td>
                                    <td class="gray text-left"><div class="ellipsis" data-toggle="tooltip" data-placement="top" title="<?php echo $taskInfo['taskName'];?>"><?php echo html::a($this->createLink('task', 'view', "id={$taskInfo['id']}"),$taskInfo['taskName']);?></div></td>
                                    <td class="gray date"><?php echo $taskInfo['estStarted'];?></td>
                                    <td class="gray date"><?php echo $taskInfo['realStarted'];?></td>
                                    <td class="gray date"><?php echo $taskInfo['deadline'];?></td>
                                    <td class="gray"><div class="ellipsis" data-toggle="tooltip" data-placement="top" title="<?php echo $taskInfo['finishedDate'];?>"><?php echo $taskInfo['finishedDate'];?></div></td>
                                    <td class="gray"><?php echo $taskInfo['estimate']; $totalPreTime += $taskInfo['estimate'];?></td>
                                <?php if($tid == 1):?>
                                    <td rowspan="<?php echo ($info['count']);?>"><?php echo $info['count']; $totalTasks += $info['count'];?></td>
                                    <td rowspan="<?php echo ($info['count']);?>"><?php echo $info['manhour']; $totalTaskTime += $info['manhour']; ?></td>
                                <?php endif;?>
                                <?php if($tid == 1 && $id == 1):?>
                                    <td rowspan="<?php echo count($load['taskSum']);?>"><?php echo $load['manhour']; $totalUserTime += $load['manhour']; ?></td>
                                <?php endif;?>
                                <?php if($tid != 1 && $id == 1) echo '</tr>'; $tid++;?>
                            <?php endforeach;?>
                            <?php endif; ?>
                        <?php endforeach;?>

                        <?php if($id != 1) echo '</tr>'; $id ++;?>
                        <?php $color = !$color;?>
                    <?php endforeach;?>
                </tr>
            <?php endforeach;?>
                <tr>
                    <td class="text-center bold">合计</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="text-right bold"><?php echo $totalPreTime; ?></td>
                    <td class="text-right bold"><?php echo $totalTasks; ?></td>
                    <td class="text-right bold"><?php echo $totalTaskTime; ?></td>
                    <td class="text-right bold"><?php echo $totalUserTime; ?></td>
                </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
      <?php endif;?>
  </div>
</div>
<a href="javascript:scroll(0,0)" style="position: fixed; right: 10px; bottom: 50px; writing-mode:lr-tb;">置顶</a>
<?php include '../../common/view/footer.html.php';?>
